package com.cea.papyrus.diagram.classdiagram.commands;

import org.eclipse.uml2.uml.ParameterableElement;
import org.eclipse.uml2.uml.TemplateParameterSubstitution;

import com.cea.papyrus.core.commands.PapyrusCommand;

public class ElementReferencedByATemplateParameterSubstitutionCreateCommand extends PapyrusCommand {

	/**
	 * Referenced element.
	 */
	private ParameterableElement child;
	
	/**
	 * parent of the created element.
	 */
	private TemplateParameterSubstitution parent ;
	
	public ElementReferencedByATemplateParameterSubstitutionCreateCommand(ParameterableElement child,
																		TemplateParameterSubstitution parent,
																		Class elementClass) {
		super(elementClass) ; // this statement is useless
		this.parent = parent ;
		this.child = child ;
	}
	
	public void execute() {
		parent.getActuals().clear() ;
		parent.getActuals().add(child) ;
	}
	
	public boolean canExecute() {
		return true ; 
	}
	
	public void redo() {
		execute() ;
	}
	
	public void undo() {
		parent.getActuals().remove(child) ;
	}
	
	public boolean canUndo() {
		return child != null ;
	}
	
	public boolean canRedo() {
		return child != null ;
	}
}
